package tech.aistar.prj.controller;

import tech.aistar.prj.model.pojo.Video;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(urlPatterns = "/video/updateView")
public class VideoUpdateViewController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Video vd = (Video) req.getAttribute("vd");

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html lang='en'>");
        out.println("<head>");
        out.println("<meta charset='UTF-8'>");
        out.println("<meta http-equiv='X-UA-Compatible' content='IE=edge'>");
        out.println("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.println("<title>bootstrap是一款响应式的UI[User-Interface]框架");out.println("</title>");
        out.println("<!-- 引入bootstrap.css - 开发环境/bootstrap.min.css - 生产环境-->");
        out.println("<link rel='stylesheet' href='/st/plugins/bootstrap-3.4.1-dist/css/bootstrap.css'>");
        out.println("<link rel='stylesheet' href='/st/css/video/release.css'>");
        out.println("</head>");
        out.println("<body>");
        out.println("<div class='container'>");
        out.println("<div class='row'>");
        out.println("<form action='/st/video/update' method='post' class='form-horizontal' role='form'>");
        out.println("<div class='form-group'>");

        //TODO...
        out.println("<input type='hidden' name='id' value='"+vd.getId()+"'>");

        out.println("<label for='firstname' class='col-sm-2 control-label'>视频标题");out.println("</label>");
        out.println("<div class='col-md-5'>");

        //将原来的封面信息封装到一个隐藏域中
        out.println("<input type='hidden' id='vdUrl' value='"+vd.getVideoUrl()+"'>");

        out.println("<input type='text' value='"+vd.getTitle()+"' class='form-control' id='title' name='title' placeholder='请输入视频标题,不要带粗口'>");
        out.println("</div>");
        out.println("</div>");
        out.println("<div class='form-group'>");
        out.println("<label for='lastname' class='col-sm-2 control-label'>视频封面");out.println("</label>");
        out.println("<div class='col-md-7'>");
        out.println("<div class='row' id='feng'>");
        out.println("<div class='col-md-3'>");

        out.println("<input type='checkbox' value='p1.jpeg' name='videoUrl'>");

        out.println("<img src='../imgs/p1.jpeg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p2.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p2.jpeg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p3.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p3.jpeg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p4.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p4.jpeg'>");
        out.println("</div>");

        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p5.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p5.jpeg'>");
        out.println("</div>");

        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p6.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p6.jpeg'>");
        out.println("</div>");

        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p7.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p7.jpeg'>");
        out.println("</div>");

        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p8.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p8.jpeg'>");
        out.println("</div>");

        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p9.jpeg' name='videoUrl'>");
        out.println("<img src='../imgs/p9.jpeg'>");
        out.println("</div>");

        out.println("</div>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<label for='firstname' class='col-sm-2 control-label'>点赞数");out.println("</label>");
        out.println("<div class='col-md-5'>");
        out.println("<input value='"+vd.getLikes()+"' readOnly type='number' class='form-control' id='likes' name='likes' placeholder='请输入点赞数'>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<label for='firstname' class='col-sm-2 control-label'>评分");out.println("</label>");
        out.println("<div class='col-md-5'>");
        out.println("<input type='number' readOnly value='"+vd.getScore()+"' class='form-control' id='score' name='score' placeholder='请输入点赞数'>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<label for='firstname' class='col-md-2 control-label'>是否发布");out.println("</label>");
        out.println("<div class='col-md-5'>");
        out.println("<label class='radio-inline'>");

        if(vd.getStatus()==0) {
            out.println("<input type='radio' checked name='status' id='status' value='0'>发布");
        }else{
            out.println("<input type='radio' name='status' id='status' value='0' checked>发布");
        }
        out.println("</label>");
        out.println("<label class='radio-inline'>");

        if(vd.getStatus()==2){
            out.println("<input checked type='radio' name='status' id='status'  value='2'>保存为草稿");
        }else{
            out.println("<input type='radio' name='status' id='status'  value='2'>保存为草稿");
        }


        out.println("</label>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<div class='col-sm-offset-2 col-sm-10'>");
        out.println("<button type='submit' class='btn btn-success'>发布");out.println("</button>");
        out.println("</div>");
        out.println("</div>");
        out.println("</form>");
        out.println("</div>");

        out.println("</div>");

        out.println("<!-- 引入jquery框架 -->");
        out.println("<script src='/st/plugins/jquery.min.js'>");out.println("</script>");

        out.println("<!-- 引入bootstrap.js/bootstrap.min.js,bootstrap依赖于jquery框架 -->");
        out.println("<script src='/st/plugins/bootstrap-3.4.1-dist/js/bootstrap.js'>");out.println("</script>");
        out.println("<script src='/st/js/video/release.js'>");out.println("</script>");
        out.println("</body>");
        out.println("</html>");
    }
}
